﻿using MediatR;
using T.Basic.API.Appliction.Command.VehicleCommand;
using T.Basic.Repository.BasicImpl;
using T.Basic.Repository.BasicInterface;

namespace T.Basic.API.Appliction.CommandHandlers.VehicleHanders
{
    /// <summary>
    /// 删除车辆信息
    /// </summary>
    public class VehicleDeleteAllCommandHandler : IRequestHandler<VehicleDeleteAllCommand, int>
    {
        private readonly IVehicleRepository _vehicleRepository;
        public VehicleDeleteAllCommandHandler(IVehicleRepository vehicleRepository)
        {
            _vehicleRepository = vehicleRepository;
        }
        public async Task<int> Handle(VehicleDeleteAllCommand request, CancellationToken cancellationToken)
        {
            var Idd = request.VehicleIds;
            foreach (var item in Idd)
            {
                var lineDel = _vehicleRepository.GetModelsAsync(item).Result;
                lineDel.IsDeleted = true;
               
                await _vehicleRepository.UpdateAsync(lineDel);

            }
            return 1;
            
        }
    }
}
